#!/usr/bin/env python
#_*_coding:utf-8_*_
from  django import forms
import os
class ArticleForm(forms.Form):
    title = forms.CharField(max_length=255,min_length=5)
    summary = forms.CharField(max_length=255,min_length=5)
    categroy_id = forms.IntegerField()
    head_img = forms.ImageField()
    content = forms.CharField(min_length=10)


def handle_uploaded_file(request,f):
    print("-->",f.name)
    base_img_upload_path = 'static/imgs'
    user_path = "%s/%s" %(base_img_upload_path,request.user.userprofile.id)
    #目录为空则创建目录
    if not os.path.exists(user_path):
        os.mkdir(user_path)
    with open("%s/%s" %(user_path,f.name),'wb+') as destination:
        for chunk in f.chunks():
            destination.write(chunk)
    #return "/static/%s/%s" %(request.user.userprofile.id,f.name)
    return "%s/%s" %(user_path,f.name)